package com.lagou.homework03;

import java.util.Objects;
public class Coder {
    private String name;
    private int age;

    public String getName() { return name; }
    public void setName(String name)  {
        //当姓名为null或者空时进行if判断
        if ( null == name || "" == name){
            //抛出异常
            try {
                throw new NameException("姓名不合理啊");
            } catch (NameException e) {
                e.printStackTrace();
            }
        }else {
            this.name = name;
        }
    }
    public int getAge() { return age; }
    public void setAge(int age)  {
        //当年龄不满足大于0或小于150时抛出异常
        if(age > 18 && age <150){
            this.age = age;
        }else{
            try {
                throw new AgeException("年龄不合理啊");
            } catch (AgeException e) {
                e.printStackTrace();
            }
        }
    }
    public Coder(String name, int age)  {
        setName(name);
        setAge(age);
    }
    public Coder() { }

    @Override
    public String toString() {
        return "Coder{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
